<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>缓存监控</title>
	<#include '/commons/include/head.ftl'>
</head>

<body>

	<div id="dg">
		<div id="toolbars" style="display:none;">
			<form id="searchForm">
				<div class="datagrid-toolbars">
					<div class="toolbar-row">
						<div class="group">
							<a onclick="freshenCache();" href="javascript:;" class="bto bto-red"><i class="fa fa-trash"></i><span>清除缓存</span></a>
							<a onclick="reload();" href="javascript:;" class="bto bto-purple1"><i class="fa fa-refresh"></i><span>刷新</span></a>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
	
	
	<script>
	var $dg ;
	$(function(){
		$dg = $("#dg").datagrid({
			title: "缓存监控",
            url: "${ctx}/manager/system/monitor/monitor_cache",
            method: 'GET', idField: "name", fit: true, 
            border: false, striped:true, 
            pagination: true, rownumbers: true, toolbar: "#toolbars", remoteSort: true, 
            sortName: 'sorting', sortOrder: 'asc',
            frozenColumns: [[
                { field: "ck", checkbox: true }
            ]],
            columns: [[ 
                { field: "name", title: "缓存名称", width: 220, formatter:function(value,row){
                	return "<span style='line-height:30px;'>"+value+"</span>" ;
                }},
                { field: "cacheHits", title: "命中次数", width: 80 },
                { field: "cacheMisses", title: "失效次数", width: 80 },
                { field: "totalCount", title: "总数量", width: 80 },
                { field: "cacheHitPercent", title: "总命中率", width: 80 }
            ]],
            onLoadSuccess: function(){
            	$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
            	$dg.datagrid('unselectAll');$dg.datagrid('uncheckAll');$dg.datagrid('clearSelections');
            },
            enableHeaderClickMenu: true, enableHeaderContextMenu: true, enableRowContextMenu: false
        });
	});
	function reload(){$dg.datagrid("reload") ;}
	
	function cacheNames() {
		var rows = $dg.datagrid('getChecked');
		var cacheNames = [];
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				if(undefined != rows[i].name && ""!=rows[i].name) {
					cacheNames.push(rows[i].name);
				}
			}
		}
		return cacheNames ;
	}	
	
	function freshenCache() {
		if(cacheNames().length == 0) {alertify.warning("请选择一条记录！");return;}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "缓存清除中，请稍等..."});
				freshenCacheAjax("${ctx}/manager/system/monitor/monitor_freshenCache", {"cacheNames" : cacheNames().join(',')}) ;
			}
		});
	}
	function freshenCacheAjax(url, params) {
		$.post(url, params, function(result) {
			if (result.status) {
				$dg.datagrid("unselectAll");$dg.datagrid("reload") ;
				alertify.success(result.message);
				$.easyui.loaded();
			} else {
				alertify.warning(result.message);
				$.easyui.loaded();
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	}
	</script>
</body>
</html>

